<?php
/**
 * Created by PhpStorm.
 * User: HuangLuSen
 * Date: 2017/5/5
 * Time: 15:29
 */

namespace app\admin\model;


use think\Cache;
use think\Db;
use think\Model;

class Position extends Model
{
    protected $autoWriteTimestamp = 'int';

    /**
     * 状态获取器
     * @param $value
     * @param $data
     * @return mixed
     */
    public function getStatusTextAttr($value, $data)
    {
        $status = [1 => '<span class="label label-success">启用</span>', 0 => '<span class="label label-danger">禁用'];
        return $status[$data['status']];
    }

    public function getAllPosition(){
        if (!empty(Cache::get('allPosition'))){
            return Cache::get('allPosition');
        }else{
            $states = Position::all();
            Cache::set('allPosition',$states);
            return $states;
        }
    }
}